package cn.sumpu.app.guoguojie.dao.impl;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import cn.sumpu.app.guoguojie.dao.PictorialTopicDao;
import cn.sumpu.app.guoguojie.domain.Doing;
import cn.sumpu.app.guoguojie.domain.DoingPictorial;
import cn.sumpu.app.guoguojie.domain.DoingPictorialTopic;
import cn.sumpu.app.guoguojie.domain.PictorialDoing;
import cn.sumpu.app.guoguojie.domain.PictorialTopic;
import cn.sumpu.app.guoguojie.exception.AppBusinessException;

public class PictorialTopicDaoImpl extends SqlSessionDaoSupport implements PictorialTopicDao {

    private static Logger logger = LoggerFactory.getLogger(PictorialTopicDaoImpl.class);

    //添加画报标签
    @Override
    public void addPictorialTopic(PictorialTopic pictorialTopic) throws AppBusinessException {
        try {
            getSqlSession().insert("cn.sumpu.app.guoguojie.persistence.PictorialTopicMapper.addPictorialTopic", pictorialTopic);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("addPictorialTopic database failure.", e);
            }
            throw new AppBusinessException("addPictorialTopic database failure.", e);
        }
    }

    //查询所有画报主题
    @SuppressWarnings("unchecked")
    @Override
    public List<PictorialTopic> getPictorialTopicAll(Map<String, Object> map) throws AppBusinessException {
        try {
            return getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.PictorialTopicMapper.getPictorialTopicAll", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getPictorialTopicAll database failure.", e);
            }
            throw new AppBusinessException("getPictorialTopicAll database failure.", e);
        }
    }

    @Override
    public int getPictorialTopicAllCount(Map<String, Object> map) throws AppBusinessException {
        try {
            return (Integer) getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.PictorialTopicMapper.getPictorialTopicAllCount", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("query database failure.", e);
            }
            throw new AppBusinessException("query database failure.", e);
        }
    }

    //更新画报主题
    @Override
    public void updatePictorialTopicById(PictorialTopic pictorialTopic) throws AppBusinessException {
        try {
            getSqlSession().update("cn.sumpu.app.guoguojie.persistence.PictorialTopicMapper.updatePictorialTopicById", pictorialTopic);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("updatePictorialTopicById database failure.", e);
            }
            throw new AppBusinessException("updatePictorialTopicById database failure.", e);
        }
    }

    //删除画报主题
    @Override
    public void deletePictorialTopicById(Map<String, Object> map) throws AppBusinessException {
        try {
            getSqlSession().delete("cn.sumpu.app.guoguojie.persistence.PictorialTopicMapper.deletePictorialTopicById", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("deletePictorialTopicById database failure.", e);
            }
            throw new AppBusinessException("deletePictorialTopicById database failure.", e);
        }
    }

    //给画报添加主题
    @Override
    public void addDoingPictorialTopic(Map<String, Object> map) throws AppBusinessException {
        try {
            getSqlSession().insert("cn.sumpu.app.guoguojie.persistence.PictorialTopicMapper.addDoingPictorialTopic", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("addDoingPictorialTopic database failure.", e);
            }
            throw new AppBusinessException("addDoingPictorialTopic database failure.", e);
        }
    }

    //删除画报主题
    @Override
    public void deleteDoingPictorialTopic(Map<String, Object> map) throws AppBusinessException {
        try {
            getSqlSession().delete("cn.sumpu.app.guoguojie.persistence.PictorialTopicMapper.deleteDoingPictorialTopic", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("deleteDoingPictorialTopic database failure.", e);
            }
            throw new AppBusinessException("deleteDoingPictorialTopic database failure.", e);
        }
    }

    //根据名称查询画报主题的个数
    @Override
    public int getPictorialTopicByName(Map<String, Object> map) throws AppBusinessException {
        try {
            return (Integer) getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.PictorialTopicMapper.getPictorialTopicByName", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getPictorialTopicByName database failure.", e);
            }
            throw new AppBusinessException("getPictorialTopicByName database failure.", e);
        }
    }

    //根据画报ID查询画报主题
    @SuppressWarnings("unchecked")
    @Override
    public List<PictorialTopic> getPictorialTopicByID(Map<String, Object> map) throws AppBusinessException {
        try {
            return (List<PictorialTopic>) getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.PictorialTopicMapper.getPictorialTopicByID", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getPictorialTopicByID database failure.", e);
            }
            throw new AppBusinessException("getPictorialTopicByID database failure.", e);
        }
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<DoingPictorial> getLastTopicMember(Map<String, Object> map) throws AppBusinessException {
        try {
            return (List<DoingPictorial>) getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.PictorialTopicMapper.getLastTopicMember", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getLastTopicMember database failure.", e);
            }
            throw new AppBusinessException("getLastTopicMember database failure.", e);
        }
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<String> getLastPictorail6(Map<String, Object> map) throws AppBusinessException {
        try {
            return (List<String>) getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.PictorialTopicMapper.getLastPictorail6", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getLastPictorail4 database failure.", e);
            }
            throw new AppBusinessException("getLastPictorail4 database failure.", e);
        }
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<String> getLastPicUrl6(Map<String, Object> map) throws AppBusinessException {
        try {
            return (List<String>) getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.PictorialTopicMapper.getLastPicUrl6", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getLastPicUrl4 database failure.", e);
            }
            throw new AppBusinessException("getLastPicUrl4 database failure.", e);
        }
    }

    @Override
    public void deletePictorialTopicByTopic(String topicId) throws AppBusinessException {
        try {
            getSqlSession().delete("cn.sumpu.app.guoguojie.persistence.PictorialTopicMapper.deletePictorialTopicByTopic", topicId);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("deletePictorialTopicByTopic database failure.", e);
            }
            throw new AppBusinessException("deletePictorialTopicByTopic database failure.", e);
        }
    }

    @Override
    public void updatePictorialSort(Map<String, Object> map) throws AppBusinessException {
        try {
            getSqlSession().update("cn.sumpu.app.guoguojie.persistence.PictorialTopicMapper.updatePictorialSort", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("update database failure.", e);
            }
            throw new AppBusinessException("update database failure.", e);
        }

    }

    @Override
    public void delPicFromTopic(Map<String, Object> map) throws AppBusinessException {
        try {
            getSqlSession().delete("cn.sumpu.app.guoguojie.persistence.PictorialTopicMapper.delPicFromTopic", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("delete database failure.", e);
            }
            throw new AppBusinessException("delete database failure.", e);
        }
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<PictorialTopic> getPictorialTopic(Map<String, Object> map) throws AppBusinessException {
        try {
            return getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.PictorialTopicMapper.getPictorialTopic", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getPictorialTopic database failure.", e);
            }
            throw new AppBusinessException("getPictorialTopic database failure.", e);
        }
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<DoingPictorialTopic> getTopicPictorial(Map<String, Object> map) throws AppBusinessException {
        try {
            return getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.PictorialTopicMapper.getTopicPictorial", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getTopicPictorial database failure.", e);
            }
            throw new AppBusinessException("getTopicPictorial database failure.", e);
        }
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<PictorialDoing> getPictorialDoing(Map<String, Object> map) throws AppBusinessException {
        try {
            return getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.PictorialTopicMapper.getPictorialDoing", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getPictorialDoing database failure.", e);
            }
            throw new AppBusinessException("getPictorialDoing database failure.", e);
        }
    }

    @Override
    public void updateTopicPictorial(DoingPictorialTopic doingPictorialTopic) throws AppBusinessException {
        try {
            getSqlSession().update("cn.sumpu.app.guoguojie.persistence.PictorialTopicMapper.updateTopicPictorial", doingPictorialTopic);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("updateTopicPictorial failure.", e);
            }
            throw new AppBusinessException("updateTopicPictorial failure.", e);
        }
    }

    @Override
    public void updatePictorialDoing(PictorialDoing pictorialDoing) throws AppBusinessException {
        try {
            getSqlSession().update("cn.sumpu.app.guoguojie.persistence.PictorialTopicMapper.updatePictorialDoing", pictorialDoing);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("pictorialDoing failure.", e);
            }
            throw new AppBusinessException("pictorialDoing failure.", e);
        }
    }

    @Override
    public Integer getTopicMinSort(Map<String, Object> map) throws AppBusinessException {
        try {
            Object obj = getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.PictorialTopicMapper.getTopicMinSort", map);
            return (Integer) (obj);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getTopicMinSort failure.", e);
            }
            throw new AppBusinessException("getTopicMinSort failure.", e);
        }
    }

    @Override
    public Integer getTopicPictorialMinSort(Map<String, Object> map) throws AppBusinessException {
        try {
            Object obj = getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.PictorialTopicMapper.getTopicPictorialMinSort", map);
            return (Integer) (obj);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getTopicPictorialMinSort failure.", e);
            }
            throw new AppBusinessException("getTopicPictorialMinSort failure.", e);
        }
    }

    @Override
    public Integer getPictorialDoingMinSort(Map<String, Object> map) throws AppBusinessException {
        try {
            Object obj = getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.PictorialTopicMapper.getPictorialDoingMinSort", map);
            return (Integer) (obj);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getPictorialDoingMinSort failure.", e);
            }
            throw new AppBusinessException("getPictorialDoingMinSort failure.", e);
        }
    }

    @Override
    public int getTopicPictorialCount(Map<String, Object> map) throws AppBusinessException {
        try {
            Object obj = getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.PictorialTopicMapper.getTopicPictorialCount", map);
            return (Integer) (obj = obj == null ? 0 : obj);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getTopicPictorialCount failure.", e);
            }
            throw new AppBusinessException("getTopicPictorialCount failure.", e);
        }
    }

    @Override
    public void insertTopicPictorial(DoingPictorialTopic dpt) throws AppBusinessException {
        try {
            getSqlSession().insert("cn.sumpu.app.guoguojie.persistence.PictorialTopicMapper.insertTopicPictorial", dpt);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("insertTopicPictorial failure.", e);
            }
            throw new AppBusinessException("insertTopicPictorial failure.", e);
        }
    }

    @Override
    public int getPictorialDoingCount(Map<String, Object> map) throws AppBusinessException {
        try {
            Object obj = getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.PictorialTopicMapper.getPictorialDoingCount", map);
            return (Integer) (obj = obj == null ? 0 : obj);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getPictorialDoingCount failure.", e);
            }
            throw new AppBusinessException("getPictorialDoingCount failure.", e);
        }
    }

    @Override
    public int getPictorialCount(Map<String, Object> map) throws AppBusinessException {
        try {
            Object obj = getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.PictorialTopicMapper.getPictorialCount", map);
            return (Integer) (obj = obj == null ? 0 : obj);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getPictorialCount failure.", e);
            }
            throw new AppBusinessException("getPictorialCount failure.", e);
        }
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<Doing> getDoing(Map<String, Object> map) throws AppBusinessException {
        try {
            return getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.PictorialTopicMapper.getDoing", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getDoing database failure.", e);
            }
            throw new AppBusinessException("getDoing database failure.", e);
        }
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<DoingPictorial> getPictorial(Map<String, Object> map) throws AppBusinessException {
        try {
            return getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.PictorialTopicMapper.getPictorial", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getPictorial database failure.", e);
            }
            throw new AppBusinessException("getPictorial database failure.", e);
        }
    }

    @Override
    public void insertPictorialDoing(PictorialDoing pictorialDoing) throws AppBusinessException {
        try {
            getSqlSession().insert("cn.sumpu.app.guoguojie.persistence.PictorialTopicMapper.insertPictorialDoing", pictorialDoing);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("insertPictorialDoing failure.", e);
            }
            throw new AppBusinessException("insertPictorialDoing failure.", e);
        }
    }

    @Override
    public void deletePictorialDoing(Map<String, Object> map) throws AppBusinessException {
        try {
            getSqlSession().delete("cn.sumpu.app.guoguojie.persistence.PictorialTopicMapper.deletePictorialDoing", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("deletePictorialDoing failure.", e);
            }
            throw new AppBusinessException("deletePictorialDoing failure.", e);
        }
    }
    
    @SuppressWarnings("unchecked")
    @Override
    public List<DoingPictorial> getDoingPictorialForname(Map<String, Object> map) throws AppBusinessException {
        try {
            return getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.PictorialTopicMapper.getDoingPictorialForname", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getDoingPictorialForname database failure.", e);
            }
            throw new AppBusinessException("getDoingPictorialForname database failure.", e);
        }
    }
    @SuppressWarnings("unchecked")
    @Override
    public List<DoingPictorial> getOneForcreator(Map<String, Object> map) throws AppBusinessException {
        try {
            return getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.PictorialTopicMapper.getOneForcreator", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getOneForcreator database failure.", e);
            }
            throw new AppBusinessException("getOneForcreator database failure.", e);
        }
    }
    
}
